package homework14;

import java.io.*;

@SuppressWarnings({"all"})

public class CustomerChart implements Serializable{
    Customer customer = new Customer();
    private String address;

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Override
    public String toString() {
        return "CustomerChart{" +
                "customerChart=" + customer +
                ", address='" + address + '\'' +
                '}';
    }
    //使用序列化技术实现深克隆
    public CustomerChart deepClone() throws IOException, ClassNotFoundException,
            OptionalDataException
    {
        //将对象写入流中
        ByteArrayOutputStream bao = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bao);
        oos.writeObject(this);

        //将对象从流中取出
        ByteArrayInputStream bis = new  ByteArrayInputStream(bao.toByteArray());
        ObjectInputStream ois = new  ObjectInputStream(bis);
        return  (CustomerChart)ois.readObject();
    }
}
